<?php

namespace app\api\controller;

use app\BaseController;
use app\api\model\Singers as ModelSingers;
use think\Request;

class Singer extends BaseController
{
    public function index(Request $request)
    {
        $limit   = isset($request['limit']) ? $request['limit'] : 10;
        $keyword = isset($request['keyword']) ? $request['keyword'] : null;

        $query = ModelSingers::whereNull('deleted_at');

        if ($keyword) {
            $query->whereLike('singer_name', '%' . $keyword . '%');
        }

        $query->order('id desc');

        $list = $query->paginate($limit);

        return JsonData(SUCCESS_CODE, "成功", $list);
    }

    public function read($id)
    {
        $item = ModelSingers::where(['id' => $id, 'deleted_at' => null])->find();

        return JsonData(SUCCESS_CODE, "成功", $item);
    }
}